package com.zhulong.saas.cloud.gateway.customize;

import com.zhulong.saas.cloud.gateway.adapt.UserAdapt;
import com.zhulong.saas.cloud.gateway.security.AuthorizeExchangeSpecCustomizer;
import com.zhulong.saas.cloud.gateway.security.SubjectBusTypeEnum;
import com.zhulong.saas.cloud.gateway.security.TenantSubjectReactiveAuthorizationManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.web.server.ServerHttpSecurity;

import java.util.Arrays;

/**
 * 采购费用的配置
 */
public class PurchaseCostExchangeSpec implements AuthorizeExchangeSpecCustomizer {

    @Autowired
    private UserAdapt userAdapt;

    @Override
    public void customize(ServerHttpSecurity.AuthorizeExchangeSpec authorizeExchangeSpec) {

        TenantSubjectReactiveAuthorizationManager cgAuthorization = new TenantSubjectReactiveAuthorizationManager(Arrays.asList(SubjectBusTypeEnum.TENDER, SubjectBusTypeEnum.AGENCE), userAdapt);
        TenantSubjectReactiveAuthorizationManager tbAuthorization = new TenantSubjectReactiveAuthorizationManager(Arrays.asList(SubjectBusTypeEnum.BIDDER), userAdapt);

        authorizeExchangeSpec.pathMatchers("/purchase-cost/cg/**").access(cgAuthorization)
                .pathMatchers("/purchase-cost/tb/**").access(tbAuthorization);

    }
}
